//
//  ZYCStuNotAttendanceRecordCell.m
//  ZDSC
//
//  Created by ZDTX on 2021/7/27.
//

#import "ZYCStuNotAttendanceRecordCell.h"
#import "ZYCAttendanceRecordModel.h"

@interface ZYCStuNotAttendanceRecordCell ()

@property (nonatomic, strong) UILabel *nameLabel;
@property (nonatomic, strong) UIButton *modifyButton;
@end
@implementation ZYCStuNotAttendanceRecordCell

- (void)setType:(ZYCStuAttendanceType)type{
    _type = type;
    if (type == ZYCStuAttendanceTypeRecord) {
        _modifyButton.hidden = YES;
    }
}

- (void)setModel:(ZYCAttendanceRecordModel *)model{
    _model = model;
    _nameLabel.attributedText = [self returnFuwenBen:[NSString stringWithFormat:@"%@/%@",model.studentName,model.attendanceStatusStr]];
}

- (NSMutableAttributedString *)returnFuwenBen:(NSString *)string{
    NSMutableAttributedString *attriString = [[NSMutableAttributedString alloc] initWithString:string];
    NSRange rang0 = NSMakeRange(0, self.model.studentName.length);
    [attriString addAttribute:NSFontAttributeName value:kCustomFont(@"PingFangSC-Medium", 17.0f) range:rang0];
    [attriString addAttribute:NSForegroundColorAttributeName value:HEX_RGB(@"#2B302D") range:rang0];
    return attriString;;
    
}

- (void)setDict:(NSDictionary *)dict{
    _dict = dict;
    _nameLabel.text = dict[@"name"];
}
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        [self.contentView addSubview:self.nameLabel];
        [self.contentView addSubview:self.modifyButton];
        [self.nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.contentView).offset(19.0f);
            make.top.equalTo(self.contentView).offset(20.0f);
        }];
        [self.modifyButton mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(self.contentView).offset(-19.0f);
            make.centerY.equalTo(self.nameLabel);
        }];

    }
    return self;
}

- (UILabel *)nameLabel {
    if (!_nameLabel) {
        _nameLabel = [UILabel LabelWithFont:kCustomFont(@"PingFangSC-Regular", 14.0f) titleColor:HEX_RGB(@"#262A28") textAlignment:ZZTextAlignmentLeft];
    }
    return _nameLabel;
}

- (UIButton *)modifyButton {
    if (!_modifyButton) {
        _modifyButton = [UIButton buttonWithType:UIButtonTypeCustom];
        _modifyButton.titleLabel.font = kCustomFont(@"PingFangSC-Light", 15.0f);
        NSMutableAttributedString *str = [[NSMutableAttributedString alloc] initWithString:@"修改状态"];
        NSRange strRange = {0,[str length]};
        [str addAttribute:NSUnderlineStyleAttributeName value:[NSNumber numberWithInteger:NSUnderlineStyleSingle] range:strRange];
        [str addAttribute:NSForegroundColorAttributeName value:HEX_RGB(@"2079D3") range:strRange];
        [_modifyButton setAttributedTitle:str forState:UIControlStateNormal];//这个状态要加上
        [_modifyButton addTarget:self action:@selector(clickModifyAction:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _modifyButton;
}

-(void)clickModifyAction:(UIButton *)sender{
    if ([self.delegate respondsToSelector:@selector(studentNotAttendanceRecordCellDidModify:)]) {
        [self.delegate studentNotAttendanceRecordCellDidModify:self.model];
    }
}

@end
